package com.ruoyi.web.core.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import java.io.IOException;

@Configuration
public class IndexConfig{

    @Value(value = "${server.port}")
    private String port;

    @EventListener({ApplicationReadyEvent.class})//监听启动类
    void applicationReadyEvent() {
        System.out.println("应用已经准备就绪 ... 启动浏览器");
        String url = "http://localhost:"+port+"/login";//填写你项目路由
        Runtime runtime = Runtime.getRuntime();
        System.out.println("当前ruantime="+System.getProperty("os.name")+"@");
        if(System.getProperty("os.name").contains("Windows"))
        {
            try {
                runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
